-
Notifications
You must be signed in to change notification settings - Fork 2
TRON integration #556
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: testnet
Are you sure you want to change the base?
TRON integration #556
Conversation
WalkthroughThe pull request adds TRON blockchain network support across the SDK and application layer. Changes include configuring TRON network endpoints, implementing TRON payment handling via JSON-RPC, adding TRON to the chain registry, enforcing mainnet-only identity checks for TRON and Solana, and adding special validation for TRON serialized transaction objects. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
||||||||||||||||||||||||
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
|||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Fix all issues with AI Agents 🤖
In @src/utilities/validateUint8Array.ts:
- Around line 20-24: The duck-typing guard in validateUint8Array.ts (the
isSerializedTx check inside the function handling input) is too fragile; update
it to explicitly document that it targets TRON serialized transaction objects
and strengthen it by validating types for 'signature' (e.g., Array or
Uint8Array), 'txID' (string), and 'raw_data' (object) rather than just checking
property presence, so the function only returns input when it confidently
matches a TRON tx and avoids false positives for other chains.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/libs/blockchain/gcr/gcr_routines/identityManager.ts (1)
146-154: Address inconsistency between identity validation and payment execution for mainnet-only chains.The mainnet-only validation is a good improvement, but it creates an architectural inconsistency:
identityManager.tsrestricts both TRON and Solana to mainnet only (lines 146-154), yetpay.tsline 50 can access testnet/shasta/nile endpoints for TRON viachainProviders[operation.chain][operation.subchain]. This means users cannot register testnet identities, but the payment system can process testnet transactions.Additionally, with both chains restricted to mainnet and no test files in the codebase, the testing strategy for identity flows is unclear. Consider either:
- Enforcing the mainnet-only policy consistently by restricting
chainProvidersaccess in payment execution, or- Allowing testnet identities by removing the restriction and documenting why certain chains require mainnet only
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (4)
sdk/localsdk/multichain/configs/chainProviders.tssrc/features/multichain/routines/executors/pay.tssrc/libs/blockchain/gcr/gcr_routines/identityManager.tssrc/utilities/validateUint8Array.ts
🔇 Additional comments (4)
src/libs/blockchain/gcr/gcr_routines/identityManager.ts (2)
16-16: LGTM! TRON import added.The TRON import is correctly added alongside other chain SDKs.
46-46: LGTM! TRON chain registration added.TRON has been properly registered in the chains map, consistent with other supported chains.
sdk/localsdk/multichain/configs/chainProviders.ts (1)
53-58: TRON endpoint configuration is correct.Verification confirms all endpoints are accurate:
- Mainnet (
https://api.trongrid.io), Shasta testnet (https://api.shasta.trongrid.io), and Nile testnet (https://nile.trongrid.io) match official TronGrid documentation.testnetandshastaintentionally share the same URL because Shasta is TRON's designated testnet.- The
nileendpoint correctly uses thehttps://nile.trongrid.ioURL pattern without the/apiprefix, per official specification.No changes needed.
src/features/multichain/routines/executors/pay.ts (1)
101-103: LGTM! The TRON case correctly follows the established pattern.The implementation is consistent with other JSON RPC chains (Solana, TON, NEAR, BTC) and properly uses
genericJsonRpcPaywithmultichain.TRONwhich is correctly exported from the SDK.
| // Skip conversion for transaction objects that are not meant to be Uint8Arrays | ||
| const isSerializedTx = 'signature' in input && 'txID' in input && 'raw_data' in input | ||
| if (isSerializedTx) { | ||
| return input | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major
Make the transaction object detection more explicit and robust.
The current guard uses duck typing to identify serialized transaction objects, which is fragile and could match unintended objects. Consider:
- The check doesn't validate that the properties have the expected types
- There's no documentation indicating this is TRON-specific
- Other chains might have similar property names, causing false positives
🔎 Proposed improvements
- // Skip conversion for transaction objects that are not meant to be Uint8Arrays
- const isSerializedTx = 'signature' in input && 'txID' in input && 'raw_data' in input
- if (isSerializedTx) {
- return input
- }
+ // Skip conversion for TRON serialized transaction objects
+ // TRON transactions contain signature (array), txID (string), and raw_data (object)
+ const isTronSerializedTx =
+ 'signature' in input &&
+ 'txID' in input &&
+ 'raw_data' in input &&
+ Array.isArray((input as any).signature) &&
+ typeof (input as any).txID === 'string' &&
+ typeof (input as any).raw_data === 'object'
+ if (isTronSerializedTx) {
+ return input
+ }This adds:
- Explicit documentation that this is for TRON transactions
- Type validation for the three properties to reduce false positives
- Clear intent for future maintainers
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // Skip conversion for transaction objects that are not meant to be Uint8Arrays | |
| const isSerializedTx = 'signature' in input && 'txID' in input && 'raw_data' in input | |
| if (isSerializedTx) { | |
| return input | |
| } | |
| // Skip conversion for TRON serialized transaction objects | |
| // TRON transactions contain signature (array), txID (string), and raw_data (object) | |
| const isTronSerializedTx = | |
| 'signature' in input && | |
| 'txID' in input && | |
| 'raw_data' in input && | |
| Array.isArray((input as any).signature) && | |
| typeof (input as any).txID === 'string' && | |
| typeof (input as any).raw_data === 'object' | |
| if (isTronSerializedTx) { | |
| return input | |
| } |
🤖 Prompt for AI Agents
In @src/utilities/validateUint8Array.ts around lines 20-24, The duck-typing
guard in validateUint8Array.ts (the isSerializedTx check inside the function
handling input) is too fragile; update it to explicitly document that it targets
TRON serialized transaction objects and strengthen it by validating types for
'signature' (e.g., Array or Uint8Array), 'txID' (string), and 'raw_data'
(object) rather than just checking property presence, so the function only
returns input when it confidently matches a TRON tx and avoids false positives
for other chains.



PR Type
Enhancement
Description
Add TRON blockchain network support with mainnet and testnet endpoints
Integrate TRON into pay operation handler using generic JSON-RPC
Register TRON chain in identity manager with mainnet-only validation
Improve Uint8Array validation to skip TRON transaction serialization
Diagram Walkthrough
File Walkthrough
chainProviders.ts
Add TRON network provider endpointssdk/localsdk/multichain/configs/chainProviders.ts
nile endpoints
pay.ts
Integrate TRON into pay operation handlersrc/features/multichain/routines/executors/pay.ts
identityManager.ts
Register TRON in identity manager with validationsrc/libs/blockchain/gcr/gcr_routines/identityManager.ts
validateUint8Array.ts
Skip Uint8Array conversion for TRON transactionssrc/utilities/validateUint8Array.ts
raw_data properties
Summary by CodeRabbit
New Features
Bug Fixes
✏️ Tip: You can customize this high-level summary in your review settings.